www.gusucode.com > VC++ 雷达模拟视频扫描程序 > VC++ 雷达模拟视频扫描程序/gusucode/坐标转换(苏晓宏)/canvasFrame.cpp
//Download by http://www.NewXing.com // canvasFrame.cpp : implementation file // #include "stdafx.h" #include "canvasr.h" #include "canvasFrame.h" #include "Calculate.h" #include "math.h" #ifdef _DEBUG #define new DEBUG_NEW #undef THIS_FILE static char THIS_FILE[] = __FILE__; #endif //////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////// // canvasFrame IMPLEMENT_DYNCREATE(canvasFrame, CFrameWnd) int p,q; double m,n; float num[2048]; int n_num[1024][512];//1024行*512列 canvasFrame::canvasFrame() { Create(NULL,"坐标转换窗口"); CClientDC dc(this); int width=dc.GetDeviceCaps(HORZRES); int height=dc.GetDeviceCaps(VERTRES); GetWindowRect(&rect); width=(width-(rect.right-rect.left))/2 ; height=(height-(rect.bottom-rect.top))/2 ; MoveWindow(width,height,(rect.right-rect.left),(rect.bottom-rect.top),true); filldate(); fill_again(); SetTimer(1,6000,NULL);//设置定时器,检验6秒显示是否可能 } canvasFrame::~canvasFrame() { } BEGIN_MESSAGE_MAP(canvasFrame, CFrameWnd) //{{AFX_MSG_MAP(canvasFrame) ON_WM_TIMER() ON_WM_PAINT() //}}AFX_MSG_MAP END_MESSAGE_MAP() ///////////////////////////////////////////////////////////////////////////// // canvasFrame message handlers //============================================================= void canvasFrame::OnTimer(UINT nIDEvent) { Invalidate();//对定时器进行响应,每6秒调用OnPaint()函数,进行重画 CFrameWnd::OnTimer(nIDEvent); } void canvasFrame::compositor(int numb)//对数组排序(从小到大) { float *ptr; ptr=num; int done=1; int i,j; float temp; j=numb; while(j>1) { j=j/2; do { done=1; for(i=0;i<(numb-j);i++) { if(ptr[i]>ptr[i+j]) { temp=ptr[i]; ptr[i]=ptr[i+j]; ptr[i+j]=temp; done=0; } } }while(done!=0); } // num_array=ptr; }//排序采用的是quick sort (快速排序法) void canvasFrame::filldate() { CCalculate c;//自定义CCalulate类,实现对余弦求值(含正弦值) c.caluateval();//对正弦余弦求值 int n=2048; for(int i=0;i<2048;i++)//把Ccalculate中的数组值赋给数组num[2048] { float *ptrf; ptrf=num; ptrf[i]=c.ptr[i];//将CCalulate计算cos的值对应赋给数组num } compositor(n);//对已量化的一个变化区间的数组num进行排序 } //==================================================== void canvasFrame::fill_again() { float val; int x; float *ptr; ptr=num; for(int i=0;i<1024;i++) { for(int j=0;j<512;j++) { val=ptr[2047-i]; x=(int)(val*j); n_num[i][j]=x; } } } //==================================================== //void Delete2DArray( void canvasFrame::OnPaint() //采用查表法,画点显示 { CPaintDC dc(this); // device context for painting RECT rect; GetClientRect(&rect); dc.SetMapMode(MM_ISOTROPIC); dc.SetWindowExt(1024,1024); dc.SetViewportExt(rect.right,-rect.bottom); dc.SetViewportOrg(rect.right/2,rect.bottom/2); dc.TextOut(500,-460," 模拟显示雷达全屏数据......"); //====================================================new for(int i=0;i<4096;i++) { if(i<=1023) { for(int j=0;j<512;j++) { SetPixel(dc,n_num[i][j],n_num[1023-i][j],RGB(0,0,0)); } } if(i>1023&&i<=2048) { for(int j=0;j<512;j++) { SetPixel(dc,-n_num[2048-i][j],n_num[i-1024][j],RGB(0,0,0)); } } if(i>2048&&i<=3072) { for(int j=0;j<512;j++) { SetPixel(dc,-n_num[i-2048][j],-n_num[3072-i][j],RGB(0,0,0)); } } if(i>3072&&i<4096) { for(int j=0;j<512;j++) { SetPixel(dc,n_num[4096-i][j],-n_num[i-3072][j],RGB(0,0,0)); } } } }